<?php
/**
 * YOS.
 * 7/24/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateFastappAccountTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        //初始化自增id uid用户id uno用户编号 did默认编号 sid子编号
        redis()->hMSet('gene', ['uid' => 50000, 'uno' => 7000000, 'did' => 33110000, 'sid' => 60000]);
        Schema::create('account', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户账号表');
            $table->bigIncrements('id')->comment('用户ID，主键')->unsigned();
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->char('username', 64)->nullable()->comment('用户名');
            $table->char('code', 8)->nullable()->comment('手机区号')->default(86);
            $table->char('mobile', 16)->nullable()->comment('手机');
            $table->char('email', 64)->nullable()->comment('用户邮箱');
            $table->char('password', 128)->nullable()->comment('密码');
            $table->tinyInteger('status')->nullable()->comment('1正常2停用3注销')->default(1);
            $table->char('last_ip', 64)->nullable()->comment('最后登陆IP');
            $table->timestamp('last_at')->nullable()->comment('最后登陆时间');
            $table->integer('type')->nullable()->comment('入口类型 常规<500000 700001游戏 800001交易所')->unsigned()->default(1);
            $table->integer('channel')->nullable()->comment('渠道')->unsigned()->default(1);
            $table->bigInteger('no')->nullable()->comment('用户编号')->unsigned();
            $table->bigInteger('gene_id')->nullable()->comment('uid')->unsigned();
            $table->char('invite_code', 32)->nullable()->comment('邀请码');
            $table->unique(['username', 'type', 'channel']);
            $table->unique(['mobile', 'code', 'type', 'channel']);
            $table->unique(['email', 'type', 'channel']);
            $table->unique('no');
            $table->unique('gene_id');
            $table->unique('invite_code');
            $table->index('channel');
        });
        Schema::create('account_info', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户信息表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->char('nickname', 64)->nullable()->comment('用户昵称');
            $table->char('name', 64)->nullable()->comment('姓名');
            $table->tinyInteger('gender')->nullable()->comment('性别1男2女')->unsigned()->default(0);
            $table->char('avatar', 64)->nullable()->comment('用户头像');
            $table->char('signed')->nullable()->comment('个人签名');
            $table->date('birthday')->nullable()->comment('生日');
            $table->char('province', 64)->nullable();
            $table->char('city', 64)->nullable();
            $table->char('district', 64)->nullable();
            $table->char('address')->nullable()->comment('住址');
            $table->smallInteger('height')->nullable()->comment('身高')->unsigned();
            $table->smallInteger('weight')->nullable()->comment('体重')->unsigned();
            $table->char('qualification', 32)->nullable()->comment('学历');
            $table->char('work', 32)->nullable()->comment('职业');
            $table->bigInteger('user_id')->nullable()->comment('用户id')->unsigned();
            $table->char('lang', 8)->nullable();
            $table->unique('user_id');
            $table->index('lang');
        });
        Schema::create('account_setting', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('账户设置');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('key', 32)->comment('key');
            $table->char('val', 64)->nullable()->comment('val');
            $table->unique(['user_id', 'key']);
        });
        Schema::create('account_wallet', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户钱包表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->bigInteger('user_id')->nullable()->comment('用户id')->unsigned();
            $table->bigInteger('currency_id')->nullable()->comment('币种id')->unsigned();
            $table->char('symbol', 8)->nullable()->comment('symbol');
            $table->char('address', 128)->nullable()->comment('address');
            $table->decimal('balance', 18, 8)->nullable()->comment('资金金额')->default(0);
            $table->decimal('balance_demo', 18, 8)->nullable()->comment('体验金额')->default(0);
            $table->decimal('balance_winnings', 18, 8)->nullable()->comment('彩金金额')->default(0);
            $table->decimal('spot', 18, 8)->nullable()->comment('现货金额')->default(0);
            $table->decimal('futures', 18, 8)->nullable()->comment('期权金额')->default(0);
            $table->decimal('contract', 18, 8)->nullable()->comment('合约金额')->default(0);
            $table->decimal('finance', 18, 8)->nullable()->comment('理财金额')->default(0);
            $table->integer('channel')->nullable()->comment('渠道')->unsigned()->default(1);
            $table->unique(['user_id', 'currency_id', 'symbol']);
            $table->index('channel');
        });
        Schema::create('account_wallet_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('钱包动帐记录表');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamp('created_at')->nullable();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('wallet_id')->comment('钱包id')->unsigned();
            $table->bigInteger('currency_id')->comment('币种id')->unsigned();
            $table->char('symbol', 8)->nullable()->comment('symbol');
            $table->tinyInteger('type')->comment('1充值')->unsigned()->default(0);
            $table->char('field', 16)->comment('账户字段')->default('balance');
            $table->tinyInteger('object_type')->comment('数据类型')->unsigned()->default(0);
            $table->bigInteger('object_id')->comment('数据id')->unsigned()->default(0);
            $table->decimal('amount', 18, 8)->comment('变动金额')->default(0);
            $table->decimal('before', 18, 8)->comment('变动前')->default(0);
            $table->decimal('after', 18, 8)->comment('变动后')->default(0);
            $table->integer('channel')->nullable()->comment('渠道')->unsigned()->default(1);
            $table->index('user_id');
            $table->index('wallet_id');
            $table->index('channel');
        });
        Schema::create('account_wallet_address', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('钱包地址');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->nullable()->comment('用户id')->unsigned();
            $table->char('symbol', 8)->nullable()->comment('symbol');
            $table->char('address', 128)->nullable()->comment('address');
            $table->char('private_key', 128)->nullable()->comment('私钥');
            $table->tinyInteger('status')->comment('初始化0否1是')->unsigned()->default(0);
            $table->char('nonce', 64)->nullable();
            $table->unique(['address', 'symbol']);
            $table->index('user_id');
        });
        Schema::create('account_wallet_address_token', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('钱包代币');
            $table->bigIncrements('id')->comment('主键');
            $table->char('address', 128);
            $table->char('symbol', 8)->comment('symbol');
            $table->char('symbol_token', 8)->nullable()->comment('代币符号');
            $table->decimal('balance', 18, 8)->nullable()->comment('账号余额')->default(0);
            $table->index('address');
            $table->index('balance');
        });
        Schema::create('account_wallet_address_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('地址动帐记录表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->tinyInteger('type')->comment('1充值')->unsigned()->default(0);
            $table->tinyInteger('status')->default(0)->unsigned();
            $table->char('symbol', 8)->comment('symbol');
            $table->char('from', 64)->nullable()->comment('from');
            $table->char('to', 64)->nullable()->comment('to');
            $table->char('symbol_token', 8)->nullable()->comment('代币符号');
            $table->char('txid', 128)->nullable()->comment('txid');
            $table->decimal('amount', 18, 8)->default(0);
            $table->timestamp('created_at')->nullable();
            $table->index('user_id');
            $table->index(['symbol', 'txid']);
        });
        Schema::create('account_realname', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户实名关联表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('realname_id')->nullable()->comment('实名id')->unsigned();
            $table->bigInteger('user_id')->nullable()->comment('用户id')->unsigned();
            $table->tinyInteger('type')->nullable()->comment('1全局')->unsigned()->default(1);
            $table->index('realname_id');
            $table->index('user_id');
        });
        Schema::create('account_other_related', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('关联三方登录表');
            $table->bigIncrements('id')->comment('主键');
            $table->tinyInteger('related_type')->comment('类型1微信公众号2微信小程序3微信登录')->unsigned();
            $table->char('unique_code', 64)->comment('三方唯一标识码');
            $table->bigInteger('user_id')->comment('用户id')->unsigned()->default(0);
            $table->integer('account_type')->unsigned()->default(1);
            $table->unique(['unique_code', 'related_type', 'account_type'], 'unique_code');
            $table->index('user_id');
        });
        Schema::create('account_other_address', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('关联地址登录表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned()->default(0);
            $table->char('symbol', 8);
            $table->char('address', 128);
            $table->integer('account_type')->unsigned()->default(1);
            $table->unique(['address', 'symbol', 'account_type'], 'address');
            $table->index('user_id');
        });
        Schema::create('account_uploadfile', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('上传文件信息表');
            $table->bigIncrements('id')->comment('主键');
            $table->tinyInteger('storage_mode')->nullable()->comment('存储模式 (1 本地 2 阿里云 3 七牛云 4 腾讯云)')->unsigned()->default(1);
            $table->char('origin_name')->nullable()->comment('原文件名');
            $table->char('object_name')->nullable()->comment('新文件名');
            $table->char('hash', 64)->nullable()->comment('文件hash');
            $table->char('mime_type', 64)->nullable()->comment('资源类型');
            $table->char('suffix', 10)->nullable()->comment('文件后缀');
            $table->bigInteger('size_byte')->nullable()->comment('字节数')->unsigned();
            $table->char('path')->nullable()->comment('path');
            $table->bigInteger('user_id')->nullable()->comment('用户id')->unsigned();
            $table->timestamps();
            $table->unique('hash');
        });
        Schema::create('account_push_client', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户推送客户端');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->nullable()->comment('用户id')->unsigned()->default(0);
            $table->char('client_id', 64)->nullable()->comment('客户端id');
            $table->tinyInteger('type')->nullable()->comment('1app')->unsigned()->default(1);
            $table->unique(['user_id', 'type']);
            $table->index('client_id');
        });
        Schema::create('account_share', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户分享');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned()->default(0);
            $table->tinyInteger('type')->comment('1邀请注册')->unsigned()->default(1);
            $table->bigInteger('object_id')->comment('数据id')->unsigned()->default(0);
            $table->date('end_at')->nullable()->comment('到期时间');
            $table->json('content')->nullable()->comment('邀请内容');
            $table->index('user_id');
        });
        Schema::create('account_event_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户事件每日活跃记录表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('event', 32)->comment('事件');
            $table->date('date')->comment('活跃绝对日期');
            $table->bigInteger('relative_day')->comment('活跃相对天数')->unsigned()->default(0);
            $table->bigInteger('total_day')->comment('累计活跃天数')->unsigned()->default(0);
            $table->unique(['user_id', 'date', 'event']);
            $table->index('event');
        });
        Schema::create('account_withdrawal', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('提现表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('currency_id')->comment('币种')->unsigned();
            $table->bigInteger('wallet_id')->comment('钱包')->unsigned();
            $table->char('code', 16)->nullable()->comment('标识');
            $table->char('trade_no', 64)->nullable()->comment('交易单号');
            $table->decimal('amount', 18, 8)->comment('金额');
            $table->decimal('charge', 16, 8)->comment('手续费')->default(0);
            $table->tinyInteger('status')->comment('审核0否1是')->unsigned()->default(0);
            $table->tinyInteger('pay_automatic')->comment('自动打款0否1是')->unsigned()->default(1);
            $table->tinyInteger('pay_status')->comment('到账成功0否1是')->unsigned()->default(0);
            $table->tinyInteger('pay_info_id')->nullable()->comment('代币为address_log_id')->unsigned();
            $table->decimal('pump', 16, 8)->comment('抽水')->default(0);
            $table->timestamps();
            $table->index('user_id');
            $table->index('wallet_id');
        });
        Schema::create('account_recharge', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('充值表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('symbol', 8)->nullable()->comment('币种');
            $table->char('code', 16)->nullable()->comment('标识');
            $table->char('trade_no', 64)->nullable()->comment('交易单号');
            $table->tinyInteger('status')->comment('1已支付')->unsigned()->default(0);
            $table->tinyInteger('recharge')->comment('成功0充余额1充游戏')->unsigned()->default(0);
            $table->decimal('amount', 11)->comment('金额')->unsigned()->default(0);
            $table->decimal('pump', 16, 8)->comment('抽水')->default(0);
            $table->addColumn('timestamp', 'pay_at', ['precision' => 0, 'comment' => '到账时间'])->nullable();
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->index('user_id');
        });
        Schema::create('account_message', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('账户消息');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('title')->nullable()->comment('标题');
            $table->string('content', 200)->nullable()->comment('内容');
            $table->bigInteger('object_id')->nullable()->comment('数据id')->unsigned();
            $table->tinyInteger('object_type')->nullable()->comment('类型')->unsigned();
            $table->tinyInteger('status')->nullable()->comment('0未读1已读')->unsigned()->default(0);
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->index('user_id');
        });
        Schema::create('account_login_log', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('账户登录日志');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('ip', 32)->nullable()->comment('ip');
            $table->char('region')->nullable()->comment('region');
            $table->char('agent')->nullable()->comment('agent');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->index('user_id');
        });
        Schema::create('account_verify', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('账户验证');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->integer('type')->nullable()->comment('1手机号2邮箱3实名')->unsigned();
            $table->integer('status')->nullable()->comment('0否1是')->unsigned();
            $table->timestamp('verify_at')->nullable()->comment('验证时间');
            $table->unique(['user_id', 'type']);
        });
        Schema::create('account_invite_level', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('邀请层级');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('parent_id')->comment('上级id')->unsigned()->default(0);
            $table->tinyInteger('status')->comment('1有效')->unsigned()->default(0);
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->text('link')->nullable()->comment('链条');
            $table->index('user_id');
            $table->index('parent_id');
        });
        Schema::create('account_invite_statistics', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('层级统计');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('level1_num')->comment('一层人数')->default(0)->unsigned();
            $table->bigInteger('level1_recharge_num')->comment('一层充值数')->default(0)->unsigned();
            $table->bigInteger('level2_num')->comment('前二层人数')->default(0)->unsigned();
            $table->bigInteger('level2_recharge_num')->comment('前二层充值数')->default(0)->unsigned();
            $table->bigInteger('level3_num')->comment('前三层人数')->default(0)->unsigned();
            $table->bigInteger('level3_recharge_num')->comment('前三层充值数')->default(0)->unsigned();
            $table->bigInteger('team_num')->comment('团队人数')->default(0)->unsigned();
            $table->bigInteger('team_recharge_num')->comment('团队充值人数')->default(0)->unsigned();
            $table->unique('user_id');
        });
        Schema::create('account_feedback', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('反馈');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->tinyInteger('type')->comment('1建议2投诉')->unsigned()->default(1);
            $table->tinyInteger('status')->comment('处理0否1是')->unsigned()->default(0);
            $table->text('content')->nullable()->comment('内容');
            $table->json('images')->nullable()->comment('图片');
            $table->text('reply')->nullable()->comment('回复');
            $table->string('remark')->nullable()->comment('备注');
            $table->timestamps();
            $table->index('user_id');
        });
        Schema::create('account_security_key', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户安全密钥');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->tinyInteger('type')->comment('1谷歌验证2邮箱3手机号')->unsigned()->default(1);
            $table->char('key')->nullable()->comment('密钥');
            $table->tinyInteger('status')->comment('激活0否1是')->unsigned()->default(0);
            $table->timestamps();
            $table->index('user_id');
        });
        Schema::create('account_pay_info', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('账户支付信息');
            $table->bigIncrements('id')->comment('主键');
            $table->softDeletes();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->tinyInteger('type')->comment('1pix2银行卡')->unsigned()->default(1);
            $table->bigInteger('account_type')->unsigned();
            $table->tinyInteger('is_lock')->comment('锁定0否1是')->unsigned()->default(0);
            $table->char('code', 6)->comment('地区code')->nullable();
            $table->char('mobile', 16)->comment('mobile')->nullable();
            $table->char('no', 32)->comment('号码')->nullable();
            $table->char('no_type', 16)->comment('no类型')->nullable();
            $table->string('bank', 32)->comment('银行')->nullable();
            $table->string('open_bank', 32)->comment('开户行')->nullable();
            $table->index('user_id');
            $table->index(['no', 'type']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('account');
        Schema::dropIfExists('account_info');
        Schema::dropIfExists('account_setting');
        Schema::dropIfExists('account_wallet');
        Schema::dropIfExists('account_wallet_log');
        Schema::dropIfExists('account_wallet_address');
        Schema::dropIfExists('account_wallet_address_token');
        Schema::dropIfExists('account_wallet_address_log');
        Schema::dropIfExists('account_realname');
        Schema::dropIfExists('account_other_related');
        Schema::dropIfExists('account_other_address');
        Schema::dropIfExists('account_uploadfile');
        Schema::dropIfExists('account_push_client');
        Schema::dropIfExists('account_share');
        Schema::dropIfExists('account_event_log');
        Schema::dropIfExists('account_withdrawal');
        Schema::dropIfExists('account_recharge');
        Schema::dropIfExists('account_message');
        Schema::dropIfExists('account_login_log');
        Schema::dropIfExists('account_verify');
        Schema::dropIfExists('account_invite_level');
        Schema::dropIfExists('account_invite_statistics');
        Schema::dropIfExists('account_feedback');
        Schema::dropIfExists('account_security_key');
        Schema::dropIfExists('account_pay_info');
    }
}
